//1.不行时间复杂度超了，最坏情况5*10^9
/*
class Solution {
public:
    void rotate(vector<int>& nums, int k) {
        k %= nums.size();
        if(k > nums.size()/2) {
            k = nums.size() - k;
            while(k--) {
                int temp = nums[0];
                for(int i = 0; i < nums.size()-1; ++i) {              
                    nums[i] = nums[i+1];
                }
                nums[nums.size()-1]= temp;

            }
            return;
        }
        while(k--) {
            int temp = nums[nums.size()-1];
            for(int i = nums.size()-1; i > 0; --i) {              
                nums[i] = nums[i-1];
            }
            nums[0]= temp;

        }
        return ;
    }
};


*/

//2.额外空间
class Solution {
public:
    void rotate(vector<int>& nums, int k) {
        vector<int> temp(nums.size(), 0);
        for(int i = 0; i < nums.size(); ++i) {
            temp[(i+k)%nums.size()] = nums[i];
        }
       
        nums.assign(temp.begin(), temp.end());
    }
};

//3.三次旋转

class Solution {
public:
    void reverse(vector<int>& nums, int start, int end) {
        while (start < end) {
            swap(nums[start], nums[end]);
            start += 1;
            end -= 1;
        }
    }

    void rotate(vector<int>& nums, int k) {
        k %= nums.size();
        reverse(nums, 0, nums.size() - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.size() - 1);
    }
};


